package com.yehun.model;


import com.alibaba.fastjson.annotation.JSONField;
import com.yehun.enums.ResultEnum;
import com.yehun.utils.StringUtils;
import lombok.Getter;
import lombok.Setter;

/**
 * Created by Genius on 2017/4/1 0001.
 */
public class RestfulModel {

    public RestfulModel() {
        this(ResultEnum.Success);
    }
    public RestfulModel(ResultEnum status) {
        this.statusEnum = status;
        this.status = this.statusEnum.getValue();
    }
    public RestfulModel(Object data) {
        this(ResultEnum.Success, data);
    }

    public RestfulModel(ResultEnum status, String message) {
        this.statusEnum = status;
        this.status = this.statusEnum.getValue();
        this.message = message;
    }
    public RestfulModel(ResultEnum status, Object data) {
        this.statusEnum = status;
        this.status = this.statusEnum.getValue();
        this.data = data;
    }

    public RestfulModel(String message, Object data) {
        this.statusEnum = ResultEnum.Success;
        this.status = this.statusEnum.getValue();
        this.message = message;
        this.data = data;
    }

    public RestfulModel(ResultEnum status, String message, Object data) {
        this.statusEnum = status;
        this.status = this.statusEnum.getValue();
        this.message = message;
        this.data = data;
    }

    @Getter
    @Setter
    private int status;

    @Getter
    @Setter
    @JSONField(serialize = false)
    private ResultEnum statusEnum;

    private String message;

    @Getter
    @Setter
    private Object data;

    public String getMessage() {
        if(StringUtils.isEmpty(this.message)) {
            if (this.statusEnum != null) {
                this.message = this.statusEnum.getText();
            }
        }
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
